package com.example.first;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class Calculate extends AppCompatActivity {
    EditText show;
    TextView type;
    TextView result;
    float answer = 0,rate=0;
    public final String TAG="calculate";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_calculate);
        Intent intent = getIntent();
        Bundle bdl = intent.getExtras();
        String a = bdl.getString("type","币种");
        rate = Float.parseFloat(bdl.getString("rate",""))/100f;
        type = findViewById(R.id.type);
        show = findViewById(R.id.input);
        result = findViewById(R.id.result1);
        type.setText(a);
    }
    public void click(View btn){
        Log.i(TAG,"click:");
        if(show.getText().toString().length()==0){
            Toast.makeText(this, "请输入数据", Toast.LENGTH_SHORT).show();
            return;
        }
        Log.i(TAG, "click: "+rate);
        answer = Float.parseFloat(show.getText().toString()) * rate;
        result.setText(String.valueOf(answer));
    }
}